﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RF35Lib;

namespace TestRF
{
    public partial class Form1 : Form
    {
        RF35Util rfutil = new RF35Util();
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            rfutil.Port=2;
            rfutil.Baud=115200;
            rfutil.Open();
            if (rfutil.IsOpen)
            {

            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            byte[] rs = rfutil.ReadBlockData(0);
            if (rs != null)
            {
                MessageBox.Show("Read Success");
            }
            else
            {
                MessageBox.Show("Read Error");
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            byte[] rs = rfutil.ReadCardSerialNum();
            
            if (rs != null)
            {
                Console.WriteLine(System.Text.Encoding.Default.GetString(rs));
                MessageBox.Show("Read Success");
            }
            else
            {
                MessageBox.Show("Read Error");
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            rfutil.UpdateSectorPassword(1, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });

        }

        private void button6_Click(object sender, EventArgs e)
        {
            rfutil.WriteBlockData(4, new byte[16] {0x00, 0x01, 0x02, 0x03,
                0x04, 0x05, 0x06, 0x07, 
                0x08, 0x09, 0x0A, 0x0B,
                0x0C, 0x0D, 0x0E, 0x0F });

        }



    }
}
